package com.aboo;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Properties;

@Slf4j
@SpringBootApplication
public class ApolloDemoApplication {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(ApolloDemoApplication.class);

        Properties properties = getDefaultProperties();
        application.setDefaultProperties(properties);
        application.run(args);
    }

    public static Properties getDefaultProperties() {
        Properties properties = new Properties();
        try {
            log.info("Loding system configuration...");
            Config config = ConfigService.getAppConfig();

            String profiles = config.getProperty("spring.profiles.active", "default");
            properties.put("spring.profiles.active", profiles);
        } catch (Exception e) {
            log.error("系统加载默认配置文件出错", e);
        }
        return properties;
    }

}
